<template>
    <div class='porlet'>
        <div class="portlet-widthout-title">
            <app-actionbar :items="actionBarModelData" @itemClick="handleItemClick"></app-actionbar>
        </div>
    </div>
</template>
<script lang='ts'>
import { Vue, Component, Prop, Provide, Emit, Watch, Model } from 'vue-property-decorator';
import { CreateElement } from 'vue';
import { Subject, Subscription } from 'rxjs';
import { ControlInterface } from '@/interface/control';
import { UIActionTool,Util } from '@/utils';
import  PortalCounterService  from '@/counter/portal/portal-counter';
import Res_usersService from '@/service/res-users/res-users-service';
import BriefReportService from './brief-report-portlet-service';

import Res_usersUIService from '@/uiservice/res-users/res-users-ui-service';


@Component({
    components: {
      
    }
})
export default class Res_usersBriefReportBase extends Vue implements ControlInterface {

    /**
     * 名称
     *
     * @type {string}
     * @memberof BriefReport
     */
    @Prop() protected name?: string;

    /**
     * 视图通讯对象
     *
     * @type {Subject<ViewState>}
     * @memberof BriefReport
     */
    @Prop() protected viewState!: Subject<ViewState>;

    /**
     * 应用上下文
     *
     * @type {*}
     * @memberof BriefReport
     */
    @Prop() protected context: any;

    /**
     * 视图参数
     *
     * @type {*}
     * @memberof BriefReport
     */
    @Prop() protected viewparams: any;

    /**
     * 视图状态事件
     *
     * @protected
     * @type {(Subscription | undefined)}
     * @memberof BriefReport
     */
    protected viewStateEvent: Subscription | undefined;

    /**
     * 获取部件类型
     *
     * @returns {string}
     * @memberof BriefReport
     */
    protected getControlType(): string {
        return 'PORTLET'
    }


    
    /**
     * PortalCounterService计数器服务对象
     *
     * @type {PortalCounterService}
     * @memberof BriefReport
     */
    protected Portalcounterservice: PortalCounterService = new PortalCounterService();

    /**
     * 计数器服务对象集合
     *
     * @type {Array<*>}
     * @memberof BriefReport
     */    
    protected counterServiceArray:Array<any> = [this.Portalcounterservice];

    /**
     * 建构部件服务对象
     *
     * @type {BriefReportService}
     * @memberof BriefReport
     */
    protected service: BriefReportService = new BriefReportService({ $store: this.$store });

    /**
     * 实体服务对象
     *
     * @type {Res_usersService}
     * @memberof BriefReport
     */
    protected appEntityService: Res_usersService = new Res_usersService({ $store: this.$store });
    

    /**
     * 逻辑事件
     *
     * @param {*} [params={}]
     * @param {*} [tag]
     * @param {*} [$event]
     * @memberof 
     */
    protected portlet_briefreport_u75d112e_click(params: any = {}, tag?: any, $event?: any) {
        // 取数
        let datas: any[] = [];
        let xData: any = null;
        // _this 指向容器对象
        const _this: any = this;
        let paramJO:any = {};
        
        let contextJO:any = {};
        xData = this;
        if (_this.getDatas && _this.getDatas instanceof Function) {
            datas = [..._this.getDatas()];
        }
        // 界面行为
        const curUIService:Res_usersUIService  = new Res_usersUIService();
        curUIService.Res_users_NewPartners(datas,contextJO, paramJO,  $event, xData,this,"Res_users");
    }

    /**
     * 逻辑事件
     *
     * @param {*} [params={}]
     * @param {*} [tag]
     * @param {*} [$event]
     * @memberof 
     */
    protected portlet_briefreport_u3336a69_click(params: any = {}, tag?: any, $event?: any) {
        // 取数
        let datas: any[] = [];
        let xData: any = null;
        // _this 指向容器对象
        const _this: any = this;
        let paramJO:any = {};
        
        let contextJO:any = {};
        xData = this;
        if (_this.getDatas && _this.getDatas instanceof Function) {
            datas = [..._this.getDatas()];
        }
        // 界面行为
        const curUIService:Res_usersUIService  = new Res_usersUIService();
        curUIService.Res_users_NewLeads(datas,contextJO, paramJO,  $event, xData,this,"Res_users");
    }

    /**
     * 逻辑事件
     *
     * @param {*} [params={}]
     * @param {*} [tag]
     * @param {*} [$event]
     * @memberof 
     */
    protected portlet_briefreport_u43d3234_click(params: any = {}, tag?: any, $event?: any) {
        // 取数
        let datas: any[] = [];
        let xData: any = null;
        // _this 指向容器对象
        const _this: any = this;
        let paramJO:any = {};
        
        let contextJO:any = {};
        xData = this;
        if (_this.getDatas && _this.getDatas instanceof Function) {
            datas = [..._this.getDatas()];
        }
        // 界面行为
        const curUIService:Res_usersUIService  = new Res_usersUIService();
        curUIService.Res_users_NewOrders(datas,contextJO, paramJO,  $event, xData,this,"Res_users");
    }


    /**
     * 关闭视图
     *
     * @param {any[]} args
     * @memberof BriefReport
     */
    protected closeView(args: any[]): void {
        let _this: any = this;
        _this.$emit('closeview', args);
    }

    /**
     *  计数器刷新
     *
     * @memberof BriefReport
     */
    public counterRefresh(){
        const _this:any =this;
        if(_this.counterServiceArray && _this.counterServiceArray.length >0){
            _this.counterServiceArray.forEach((item:any) =>{
                if(item.refreshData && item.refreshData instanceof Function){
                    item.refreshData();
                }
            })
        }
    }


    /**
     * 操作栏模型数据
     *
     * @returns {any[]}
     * @memberof BriefReport
     */
    protected actionBarModelData:any[] =[
        { viewlogicname:"portlet_briefreport_u75d112e_click",
        actionName:"新增客户",
        counterService:this.Portalcounterservice,
        counterId:"item1",
        },
        { viewlogicname:"portlet_briefreport_u3336a69_click",
        actionName:"新增商机",
        counterService:this.Portalcounterservice,
        counterId:"item2",
        },
        { viewlogicname:"portlet_briefreport_u43d3234_click",
        actionName:"新增订单",
        counterService:this.Portalcounterservice,
        counterId:"item3",
        }
    ];

    /**
     * 触发界面行为
     *
     * @memberof BriefReport
     */
    protected handleItemClick($event:any){
        if(Object.is($event,'portlet_briefreport_u75d112e_click')){
            this.portlet_briefreport_u75d112e_click(null);
        }
        if(Object.is($event,'portlet_briefreport_u3336a69_click')){
            this.portlet_briefreport_u3336a69_click(null);
        }
        if(Object.is($event,'portlet_briefreport_u43d3234_click')){
            this.portlet_briefreport_u43d3234_click(null);
        }
    }

    /**
     * 获取多项数据
     *
     * @returns {any[]}
     * @memberof BriefReport
     */
    public getDatas(): any[] {
        return [];
    }

    /**
     * 获取单项树
     *
     * @returns {*}
     * @memberof BriefReport
     */
    public getData(): any {
        return {};
    }

    /**
     * vue 生命周期
     *
     * @memberof BriefReport
     */
    protected created() {
        this.afterCreated();
    }

    /**
     * 执行created后的逻辑
     *
     *  @memberof BriefReport
     */    
    protected afterCreated(){
        if (this.viewState) {
            this.viewStateEvent = this.viewState.subscribe(({ tag, action, data }) => {
                if (!Object.is(tag, this.name)) {
                    return;
                }
                const refs: any = this.$refs;
                Object.keys(refs).forEach((_name: string) => {
                    this.viewState.next({ tag: _name, action: action, data: data });
                });
            });
        }
    }

    /**
     * vue 生命周期
     *
     * @memberof BriefReport
     */
    protected destroyed() {
        this.afterDestroy();
    }

    /**
     * 执行destroyed后的逻辑
     *
     * @memberof BriefReport
     */
    protected afterDestroy() {
        if (this.viewStateEvent) {
            this.viewStateEvent.unsubscribe();
        }
    }

}
</script>

<style lang='less'>
@import './brief-report-portlet.less';
</style>